import { createSlice } from '@reduxjs/toolkit'

const initialState = {
  start: '北京',
  end: '上海',
  date: '2025-10-28',
  isSeat: true,
  isSpeed: true,
  isDesc: true,
}

const citySlice = createSlice({
  name: 'city',
  initialState,
  reducers: {
    cityExchange(state){
        const cache = state.start;
        state.start = state.end;
        state.end = cache;
    },
    citySetIsSpeed(state, action) {
        state.isSpeed = action.payload
    },
    citySetIsSeat(state, action) {
        state.isSeat = action.payload
    },
    citySetIsDesc(state, action) {
        state.isDesc = action.payload
    },
    citySetDate(state, action) {
        state.date = action.payload
    },
    citySet(state, action) {
        state[action.payload.type] = action.payload.value
    }
  },
})

export const { cityExchange, citySetIsSpeed, citySetIsSeat, citySetIsDesc, citySetDate, citySet } = citySlice.actions

export default citySlice.reducer
